#include "viml/compiler.h"
#include "viml/vm.h"
#include <iostream>
#include <gtest/gtest.h>

TEST(DebugForLoopTest, SimpleForLoop) {
    try {
        viml::Compiler compiler;
        viml::VM vm;
        
        // 测试简单的for循环
        std::string source = R"(
let numbers = [1, 2, 3]
echo "Before loop"
for num in numbers
    echo "Number:" num
endfor
echo "After loop"
)";
        
        std::cout << "=== Source Code ===" << std::endl;
        std::cout << source << std::endl;
        
        std::cout << "\n=== Compiling ===" << std::endl;
        auto bytecode = compiler.compile(source, "test.vim");
        
        // std::cout << "\n=== Generated Bytecode ===" << std::endl;
        // bytecode->dump();
        
        std::cout << "\n=== Executing ===" << std::endl;
        auto result = vm.execute(bytecode);
        
        std::cout << "\n=== Result ===" << std::endl;
        std::cout << "Final result: " << result.to_string() << std::endl;
        
        SUCCEED();
    } catch (const std::exception& e) {
        FAIL() << "Error: " << e.what();
    }
}